package com.hzdp.web.captcha;

import java.awt.image.BufferedImage;
import java.security.SecureRandom;
import java.util.Random;

import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;

public class JMultiBackgroundGenerator implements BackgroundGenerator {

	private int imageWidth;
	private int imageHeight;
	private Random random = new SecureRandom();

	private BackgroundGenerator[] generators;

	public JMultiBackgroundGenerator(int imageWidth, int imageHeight, BackgroundGenerator[] generators) {
		this.imageWidth = imageWidth;
		this.imageHeight = imageHeight;
		this.generators = generators;
	}

	@Override
	public int getImageHeight() {
		return imageHeight;
	}

	@Override
	public int getImageWidth() {
		return imageWidth;
	}

	@Override
	public BufferedImage getBackground() {
		int index = this.random.nextInt(this.generators.length);
		return this.generators[index].getBackground();
	}

}
